﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace PlottingBasics.LINQHelpers
{
    public static class TranslateIfHelper
    {

        /// <summary>
        /// Take 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TValue"></typeparam>
        /// <param name="input"></param>
        /// <param name="cut"></param>
        /// <param name="getVal"></param>
        /// <param name="transLessThan"></param>
        /// <param name="transGEThan"></param>
        /// <returns></returns>
        public static IEnumerable<T> TranslateIf<T, TValue>(this IEnumerable<T> input, TValue cut, Func<T, TValue> getVal, Func<T, T> transLessThan, Func<T, T> transGEThan)
            where TValue : IComparable<TValue>
        {
            Func<T, T> trans = v =>
            {
                if (Comparer<TValue>.Default.Compare(getVal(v), cut) < 0)
                {
                    return transLessThan(v);
                }
                else
                {
                    return transGEThan(v);
                }
            };
            var result = from item in input
                         select trans(item);
            return result;
        }

    }
}
